Skip to main content

Syntax Basics

This page covers the core syntax you need to understand the examples in Sino.


Variables

let name = "John"
const age = 20
  • let creates a mutable variable
  • const creates an immutable variable

Functions

func add(a, b)
return a + b
end

Functions are defined with func and use end to close the block.

Lambdas

func(x) => x * 2

Short inline functions.

Block form:

func(x) do
print(x)
end

Tables (Objects)

let person = {
name = "John",
age = 20
}

Access fields:

print(person.name)

Classes

class Person
field name

func Self:new(name)
self.name = name
end

func greet()
print(self.name)
end
end

Create an instance:

let p = Person("John")
p:greet()

Arrays

let arr = [1, 2, 3]

Loop over values (uses Stdlib):

Arr:each(func(val, idx) do
print(val)
end)

Pipe Operator

data
|> transform()
|> print()

Passes the result of one step into the first argument of the next.

Destructuring

let {name, age} = person

Rename fields:

let {name: firstName} = person

Ref Types

let x := 10
let y = x

y := y^ + 5

print(x^) -- 15

Refs allow shared mutable values.

Imports

import Arr from "sino.array"